package com.e.ticket;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.material.bottomnavigation.BottomNavigationView;


public class MainActivity extends AppCompatActivity {
    private BottomNavigationView bottomNavigationView;
    private Fragment fragment1;
    private FragmentManager fragmentManager;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        bottomNavigationView = (BottomNavigationView) findViewById(R.id.navigation);
        Bundle  b= getIntent().getExtras();
        if(b==null){
            getSupportFragmentManager().beginTransaction().add(R.id.fl_content,new Index()).commit();
        }else{
            switch (b.getInt("ids")){
                case 1:
                    bottomNavigationView.setSelectedItemId(R.id.item_bottom_1);
                    getSupportFragmentManager().beginTransaction().replace(R.id.fl_content,new Index()).commit();
                    break;
                case 2:
                    bottomNavigationView.setSelectedItemId(R.id.item_bottom_2);
                    getSupportFragmentManager().beginTransaction().replace(R.id.fl_content,new Ticket_Order()).commit();
                    break;
                case 3:
                    bottomNavigationView.setSelectedItemId(R.id.item_bottom_3);
                    getSupportFragmentManager().beginTransaction().replace(R.id.fl_content,new Own()).commit();
            }
        }

        bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()){
                    case R.id.item_bottom_1:
                        getSupportFragmentManager().beginTransaction().replace(R.id.fl_content,new Index()).commit();
                        break;
                    case R.id.item_bottom_2:
                        getSupportFragmentManager().beginTransaction().replace(R.id.fl_content,new Ticket_Order()).commit();
                        break;
                    case R.id.item_bottom_3:
                        getSupportFragmentManager().beginTransaction().replace(R.id.fl_content,new Own()).commit();
                }
                return true;
            }
        });



    }
//    public void switchContent(Fragment currentFragment,Fragment toFragment){
//        FragmentTransaction transaction = fragmentManager.beginTransaction();
//        if(!toFragment.isAdded()){
//            transaction.hide(currentFragment).add(R.id.fl_content,toFragment).commit();
//        }else{
//            transaction.hide(currentFragment).show(toFragment).commit();
//        }
//    }


//  不小心看到的，复制一下，很nice

    // ┏┓　　　┏┓
// ┏┛┻━━━┛┻┓
// ┃　　　　　　　┃ 　
// ┃　　　━　　　┃
// ┃　┳┛　┗┳　┃
// ┃　　　　　　　┃
// ┃　　　┻　　　┃
// ┃　　　　　　　┃
// ┗━┓　　　┏━┛
// ┃　　　┃ 神兽保佑　　　　　　　　
// ┃　　　┃ 代码无BUG！
// ┃　　　┗━━━┓
// ┃　　　　　　　┣┓
// ┃　　　　　　　┏┛
// ┗┓┓┏━┳┓┏┛
// ┃┫┫　┃┫┫
// ┗┻┛　┗┻┛





}